<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
    <title></title>
</head>
<body>
<p>生态采样录入系统</p>
<form id="uploadForm" enctype="multipart/form-data">
    请选择文件: <input id="file" type="file" name="file"/>
</form>
<br>项目编号: <input id="project_id" type="text"><br>
<br>年度编号: <input id="year_id" type="text"><br>
<br>
<button id="upload">上传文件</button>
<br>
-----------------
<br>
项目信息：<input id="project" type="text" readonly="readonly"><br>
本次录入：<input id="insert_quantity" type="text" readonly="readonly"><br>
记录总数：<input id="record_quantity" type="text" readonly="readonly"><br>
物种总数：<input id="species_quantity" type="text" readonly="readonly"><br>
点位总数：<input id="site_quantity" type="text" readonly="readonly"><br>
</body>

<script type="text/javascript">
    var insert_quantity = document.getElementById('insert_quantity')
    var record_quantity = document.getElementById('record_quantity')
    var species_quantity = document.getElementById('species_quantity')
    var site_quantity = document.getElementById('site_quantity')
    var project = document.getElementById('project')
    $(function () {
        $("#upload").click(function () {
            var formData = new FormData()
            var file = $('#file')[0].files[0]
            var project_id = document.getElementById('project_id').value
            var year_id = document.getElementById('year_id').value
            formData.append('file', file);
            formData.append('project_id',project_id)
            formData.append('year_id',year_id)
            $.ajax({
                type: 'post',
                url: "/upload",
                data: formData,
                cache: false,
                processData: false,
                contentType: false,
            }).success(function (data) {
                console.log(data);
                console.log(data['site_quantity'])
                project.value = data['project']
                insert_quantity.value = data['insert_quantity']
                record_quantity.value = data['record_quantity']
                species_quantity.value = data['species_quantity']
                site_quantity.value = data['site_quantity']

                alert('成功上传');
            }).error(function () {
                alert("上传失败");
            });
        });
    });
</script>
</html>